home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 405_01 / MyParser.y < prev    next >
Encoding:
Text File  |  1993-07-17  |  1.1 KB  |  51 lines

  1. /* %Z% %M% %Y% %Q% %I% %E% %U% (%F%) */
  2. /*
  3.  * Nom du Fichier :     |>nom_fichier<|
  4.  * Titre :         |>Titre<|
  5.  * Auteur:        |>auteur<|
  6.  * Date de creation :    |>dateCreation<|
  7.  */
  8. /* Description :
  9.  *    Document de reference : |>doc<|
  10.  *    Objet : |>objet<|
  11.  *
  12.  */
  13. /*
  14.  * historique :
  15.  * |>date<|    |>auteur<|    |>objet<|
  16.  */
  17. /* -------------- declaration section -------------- */
  18.  
  19. %name MyParser
  20. %define LSP_NEEDED
  21. %define ERROR_BODY =0
  22. %define LEX_BODY =0
  23. %header{
  24. #include <stdio.h>
  25. %}
  26.  
  27. %union {
  28.     int itype;    /* for count */
  29.     char ctype;    /* for char */
  30.     }
  31. %token <ctype> EOL_TOKEN CHAR_TOKEN
  32. %type <itype> file line lines chars
  33. %start file
  34.  
  35. /* -------------- rules section -------------- */
  36. /* Sample parser. Does count Chars in a line, and lines in file */
  37. %%
  38. file    : lines
  39.     {printf("nlines=%d\n",$1); /* show line count */}
  40.     ;
  41. lines     : line {$$=1; /* first line of all */}
  42.     | lines line {$$=$1+1;    /* count one more line */}
  43.     ;
  44. line     : chars EOL_TOKEN {$$=$1;printf("nchars=%d\n",$1); /* show char count */}
  45.     ;
  46. chars    : CHAR_TOKEN { $$=1;/* first char of line */}
  47.     | chars CHAR_TOKEN {$$=$1+1; /* count one more char */}
  48.     ;
  49. %%
  50. /* -------------- body section -------------- */
  51.